package practise.alogrithm.hundredInterviewQuestions.secondTime;

/**
 * Created by Richard on 7/26/2014.
 */
public class AmountOneInBinary {
    public Integer getAmount_And_Operate(Integer value){
        int flag = 1;
        int count=0;
        while(flag>0){
            if((value & flag)>0){
                count++;
            }
            flag=flag<<1;
        }
        return count;
    }

    public Integer getAmount_Bit_Operate(Integer value){
        int count=0;
        while(value!=0){
            count++;
            value = value&(value-1);

        }
        return count;
    }

    public static void main(String[] args){
        AmountOneInBinary amountOneInBinary = new AmountOneInBinary();
        System.out.println("result:"+amountOneInBinary.getAmount_And_Operate(-1));
        System.out.println("result:"+amountOneInBinary.getAmount_Bit_Operate(-1));
    }
}
